import {http} from "@/utils";

import type {ResType} from "./shared.ts";
// 1. 定义具体的借口类型 频道列表
type ChannelItem = {
    id: number
    name: string
}

type ChannelRes = {
    id: string;
    channelList: ChannelItem[]
}
// 2. 定义具体的数据类型 用户列表数据
type ListItem = {
    id: string
    title: string
    status: string
    comment_count: number
    pubdate: string
    cover: {
        type: number
        images: string[]
    }
    like_count: number
    read_count: string
}

type ListRes = {
    page: number
    per_page: number
    results: ListItem[]
    total_count: number
}

type ParamsRes = {
    channel_id: string
    page: number
}

// 1. 异步请求频道列表数据
function fetchChannelListApi() {
    return http.request<ResType<ChannelRes>>({
        url: '/channels',
    })
}

// 2. 异步请求用户列表数据
function fetchListApi(params: ParamsRes) {
    return http.request<ResType<ListRes>>({
        url: '/mp/articles',
        params: params
    })
}

// 获取token
function Login() {
    return http.request({
        url: '/authorizations',
        method: 'POST',
        data: {
            mobile: '13800000002',
            code: '246810'
        }
    })
}

export {
    // 请求频道列表
    fetchChannelListApi,
    // 请求用户列表文章
    fetchListApi,
    // 获取token
    Login
};
export type {ChannelRes, ListRes};

